package com.sjlh.centurylianhua.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sjlh.centurylianhua.dto.SearchCon;
import com.sjlh.centurylianhua.entity.PurchaseLog;
import com.sjlh.centurylianhua.entity.PurchaseLogInfo;
import com.sjlh.centurylianhua.mapper.PurchaseLogInfoMapper;
import com.sjlh.centurylianhua.utils.ResultData;
import com.sjlh.centurylianhua.utils.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/purchaseInfo")
public class PurchaseInfoController {
    @Resource
    private PurchaseLogInfoMapper purchaseLogInfo;
    @RequestMapping("/add")
    public Object add(@RequestBody PurchaseLogInfo purchaseInfo) {
        System.out.println(purchaseInfo);
        long r=purchaseLogInfo.insert(purchaseInfo);
        if (r==1){
            return new ResultData(true,20000,"添加成功",true,null);
        }else {
            return new ResultData(false,20000,"添加失败",false,null);
        }
    }
    @RequestMapping("/get")
    public Object getAll(@RequestBody PurchaseLogInfo purchaseInfo){
        System.out.println(purchaseInfo);
        QueryWrapper<PurchaseLogInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("purchase_id",purchaseInfo.getPurchaseId());
        wrapper.apply("product.id = purchase_log_info.product_id");
        //判断是否分页
            List<PurchaseLogInfo> list = purchaseLogInfo.getInfo(wrapper);
            long count = purchaseLogInfo.getInfo(wrapper).size();
            ResultData rs=new ResultData(true,20000,"成功",list,count);
            return rs;
    }
}
